using System;
using System.Drawing.Printing;
using System.Windows.Forms;
using PrintTray.Properties;

namespace PrintTray
{
    delegate void SetTextDelegate(string text);

    public partial class MainForm : Form
    {

        public MainForm()
        {
            InitializeComponent();
        }

        private void MainForm_Load(object sender, EventArgs e)
        {
            if (Settings.Default.UserSettings == null)
            {
                Settings.Default.UserSettings = new UserSettings();
            }
            if (Settings.Default.UserSettings.PrintSettings == null)
            {
                Settings.Default.UserSettings.PrintSettings = new PrinterSettings();
            }

            propertyGrid.SelectedObject = Settings.Default.UserSettings;
        }

        private void OKbutton_Click(object sender, EventArgs e)
        {
            Settings.Default.Save();
            Hide();
        }

        private void cancelButton_Click(object sender, EventArgs e)
        {
            Hide();
        }

        private void applyButton_Click(object sender, EventArgs e)
        {
            Settings.Default.Save();

        }

        internal void AddLogRecord(string text)
        {
            this.Invoke(new SetTextDelegate(SetLogRecord), new object[]{text});
        }
        private void SetLogRecord(string text)
        {
            logListView.Items.Add(text);
        }
    }
}